﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PMSGSC.DAL;
using PMSGSC.BLL;

namespace PMSGSC.App.Sys
{
    public partial class frmChangePassword : DevExpress.XtraEditors.XtraForm
    {
        public frmChangePassword()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtOld.EditValue == null || txtOld.EditValue.ToString() != frmMain.UserLogin.PassWord)
            {
                XtraMessageBox.Show("Password incorrect !", "Error",  MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtNew.EditValue == null || txtConfirm.EditValue == null)
            {
                XtraMessageBox.Show("Password cannot be empty !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtNew.EditValue.ToString() != txtConfirm.EditValue.ToString())
            {
                XtraMessageBox.Show("Confirm new password incorrect !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            frmMain.UserLogin.PassWord = txtNew.EditValue.ToString();
            Employee_BLL.Update(frmMain.UserLogin);

            XtraMessageBox.Show("Change Password successly !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
                

        }
    }
}